import zodToJsonSchema from "zod-to-json-schema";
import { DatabaseParam } from "../store/types";
import { Tool, ToolCall } from "./types";



export class BaseToolProvider {
	tools: Tool[];
	database?: DatabaseParam;
	constructor() {
		this.tools = [];
	}
  async callTool(tool: ToolCall): Promise<any> {
		const curTool = this.tools.find((tool) => tool.name === tool.name);
		if (curTool && curTool?.callback) {
			await curTool.callback(tool);
		}
	}
	listTool(): Tool[] {
		return this.tools.map((item) => {
			return {
				name: item.name,
				description: item.description,
				parameters: zodToJsonSchema(
					item.parameters, {
					strictUnions: true,
				})
			};
		});
	}
	addTool(tool: Tool, callback: (call: ToolCall) => Promise<any>) {
		tool.callback = callback;
		this.tools.push(tool);
	};
}